package com.briup.serviceImp;

import com.briup.dao.ShopcarMapper;
import com.briup.pojo.Customer;
import com.briup.pojo.Shopcar;
import com.briup.service.IShopCarService;
import com.briup.utils.ToolMan;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ShopCarServiceImp implements IShopCarService {
    @Override
    public List<Shopcar> findByCustomer(Customer customer) {
        SqlSession sqlSession = ToolMan.getSqlSession();
       ShopcarMapper mapper = sqlSession.getMapper(ShopcarMapper.class);
        List<Shopcar> shopcars = mapper.selectByCustomerId(customer.getId());
        ToolMan.close(sqlSession);
        return shopcars;
    }

    @Override
    public void saveShopCar(Shopcar shopCar) {
        SqlSession sqlSession = ToolMan.getSqlSession();
        ShopcarMapper mapper = sqlSession.getMapper(ShopcarMapper.class);
        mapper.insert(shopCar);
        ToolMan.close(sqlSession);
    }

    @Override
    public void saveShopCar(List<Shopcar> cars, Integer bookId, Customer customer, int num) {

    }

    @Override
    public void updateShopCar(Shopcar shopCar) {
        SqlSession sqlSession = ToolMan.getSqlSession();
        ShopcarMapper mapper = sqlSession.getMapper(ShopcarMapper.class);
        int i = mapper.updateByPrimaryKey(shopCar);
        System.out.println(i);
        ToolMan.close(sqlSession);
    }
}
